//
//  MyLayout.m
//  UICollectionViewDemo
//
//  Created by fortsven on 14/12/22.
//  Copyright (c) 2014年 Huicent. All rights reserved.
//
#import "MyLayout.h"

@implementation MyLayout
@synthesize delegate;

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
    for(int i = 1; i < [answer count]; ++i)
    {
        UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i];
        UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1];
        NSInteger maximumSpacing = 5;
        NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
        if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width)
        {
            CGRect frame = currentLayoutAttributes.frame;
            frame.origin.x = origin + maximumSpacing;
            currentLayoutAttributes.frame = frame;
            NSLog(@"%f",frame.origin.y);        }
        if (i == answer.count-1) {
            [delegate LastCollectionViewFlowLayoutFrameY:currentLayoutAttributes.frame.origin.y];
        }
    }
    return answer;
}


//- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
//{
//
//    UICollectionViewLayoutAttributes *currentLayoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
//    if (indexPath.section == 0) {
//        currentLayoutAttributes.frame = CGRectMake(0, 0, 320, 160);
//    }
//
//    return currentLayoutAttributes;
//}


@end
